package com.hfy.kandian.controller;


import com.hfy.kandian.dao.command.BookCommand;
import com.hfy.kandian.dao.representation.BookRepresentation;
import com.hfy.kandian.entity.Book;
import com.hfy.kandian.mapper.BookMapper;
import com.hfy.kandian.service.BookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author HAN XIAOYANG
 * @since 2020-12-30
 */
@RestController
@RequestMapping("/book")
public class BookController {
    @Autowired
    private BookService bookService;

    @ApiOperation(value = "新建书籍")
    @PostMapping("/insert")
    public int insertABook(@RequestBody BookCommand bookCommand) {
        return bookService.insertABook(bookCommand);
    }


    @ApiOperation(value = "依据bookId查找书籍")
    @GetMapping("/getById/{bookId}")
    public BookRepresentation getBookById(@PathVariable int bookId) {
        return bookService.getBookById(bookId);
    }


    @ApiOperation(value = "模糊查询书籍")
    @GetMapping("/searchBook/{keyword}")
    public List<BookRepresentation> bookFuzzyQuery(@PathVariable String keyword) {
        return bookService.getBookByKeyword(keyword);
    }

    @ApiOperation(value = "修改书籍相关信息")
    @PostMapping("/modify")
    public int modify(@RequestBody Book book) {
        return bookService.modifyBook(book);
    }

    @ApiOperation(value = "展示本书所有章节")
    @GetMapping(value = "/showAllChapter/{bookId}")
    public List showAllChapter(@PathVariable int bookId) {
        return bookService.showAllChapter(bookId);
    }

    @ApiOperation(value = "展示本章的内容")
    @GetMapping(value = "/showTheContent/{bookId}/{ChapterName}")
    public String showTheContent(@PathVariable int bookId, @PathVariable String ChapterName) {
        return bookService.showTheContent(bookId, ChapterName);
    }

    @ApiOperation(value = "展示本书所有标签")
    @GetMapping(value = "/showAllTags/{bookId}")
    public List<String> showAllTags(@PathVariable int bookId){
        return bookService.showAllTags(bookId);
    }


}

